//
//  COBaseViewController.swift
//  CocoProject
//
//  Created by Ruthless on 2023/8/17.
//

import UIKit

class COBaseViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .rgba(17, 7, 41, 1)
        configUI()
    }
    
    var navShow: Bool {
        true
    }
    var navColor: UIColor {
        .clear
    }
    var shadowColor: UIColor {
        .clear
    }
    var titleColor: UIColor {
        .white
    }
    var showBack: Bool {
        true
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        let appearance = UINavigationBarAppearance()
        appearance.configureWithOpaqueBackground()
        appearance.backgroundColor = navColor
        appearance.shadowColor = shadowColor
        appearance.titleTextAttributes = [.foregroundColor: titleColor]
        self.navigationController?.navigationBar.standardAppearance = appearance
        self.navigationController?.navigationBar.scrollEdgeAppearance = appearance
        
        let item = UIBarButtonItem(customView: returnButton)
        if showBack {
            self.navigationItem.leftBarButtonItem = item
        }
        
        navigationController?.setNavigationBarHidden(!navShow, animated: true)
    }
    
    
    private lazy var returnButton: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "编组 6"), for: .normal)
        btn.addTarget(self, action: #selector(backVC), for: .touchUpInside)
        return btn
    }()
    
    func configUI() {
        
    }
}

extension COBaseViewController {
    @objc
    func backVC() {
        self.navigationController?.popViewController(animated: true)
    }
}
